import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main4 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		TreeMap<String, TreeSet<Integer>> treeMap = new TreeMap<String, TreeSet<Integer>>();
		ArrayList<String> arrayList = new ArrayList<String>();
		int count = 1;
		while(scanner.hasNextLine()){
			String string = scanner.nextLine();
			if(string.equals("!!!!!")){
				break;
			}
			arrayList.add(string);
			Scanner input = new Scanner(string);
			while(input.hasNext()){
				String str = input.next();
				if(treeMap.containsKey(str)){
					treeMap.get(str).add(count);
				}else{
					TreeSet<Integer> treeSet = new TreeSet<Integer>();
					treeSet.add(count);
					treeMap.put(str, treeSet);
				}
			}
			input.close();
			count++;
		}
		for(Entry<String, TreeSet<Integer>> entry : treeMap.entrySet()){
			System.out.println(entry.getKey() + "=" + entry.getValue());
		}
		while(scanner.hasNextLine()){
			String string = scanner.nextLine();
			Scanner input = new Scanner(string);
			if(string.length()==0){
				System.out.println("found 0 results");
				continue;
			}
			TreeSet<Integer> treeSet = treeMap.get(input.next());
			if(treeSet == null){
				System.out.println("found 0 results");
				continue;
			}else if(treeSet.isEmpty()){
				System.out.println("found 0 results");
			}else {
				System.out.println(treeSet);
				for(Integer i : treeSet){
					System.out.println("line " + i + ":" + arrayList.get(i-1));
				}
			}
			while(input.hasNext()){
				String str = input.next();
				treeSet.retainAll(treeMap.get(str));
			}
			input.close();
		}
		scanner.close();
		
	}

}
